package com.lenovo.lcdm.dcm.common.context;


import com.alibaba.ttl.TransmittableThreadLocal;
import com.lenovo.lcdm.team.entity.TeamUser;

import java.util.Optional;
import java.util.concurrent.ExecutorService;

/**
 * @author
 * @see SessionInterceptor
 * @see TtlExecutors#getTtlExecutorService(ExecutorService)   使用TTL线程池，就可以传递TTL线程上下文
 */
public class LcdmUserContext {
    private LcdmUserContext() {
    }

    private static final ThreadLocal<TeamUser> userHolder = new TransmittableThreadLocal<>();

    public static void putUser(TeamUser fullUser) {
        userHolder.set(fullUser);
    }

    public static void clear() {
        userHolder.remove();
    }

    public static TeamUser getUser() {
        return userHolder.get();
    }

    public static Optional<TeamUser> getUserOptional() {
        return Optional.ofNullable(userHolder.get());
    }
}
